<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>aspect-ratio</title>
    <style>
        .container {
            --aspect-ratio--: 16 / 9;
            position: relative;
            height: 0;
            padding-bottom: calc(100% / (var(--aspect-ratio--)));
        }

        .container>.container-img {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
    </style>
</head>

<body>
    <div class="container">
        <img src="https://picsum.photos/id/119/800/450" class="container-img" />
    </div>
</body>

</html>